#include <iostream>
#include <cstdio>
#include <queue>
#include <algorithm>
#include <memory.h>
#define MAXN 10005
using namespace std;

struct point {
    int id, v;
};

struct node {
    int v, w;
};

point p[1005];
int n, m, di;
vector <node> G[MAXN];
queue <int> q;
int num[MAXN], vis[MAXN], d[MAXN];

bool spfa (int s) {
	memset(vis, 0, sizeof(vis));
	memset(d, 0x3f,sizeof(d));
    d[s] = 0;
    q.push(s);
    num[s]++;
    while (!q.empty()) {
        int u = q.front();
        q.pop();
        vis[u] = 0;
        for (unsigned i = 0; i < G[u].size(); i++) {
            int v = G[u][i].v;
            int w = G[u][i].w;
            if (d[v] > d[u] + w) {
                d[v] = d[u] + w;
                if (!vis[v]) {
                    q.push(v);
                    num[v]++;
                    if (num[v] >= n) {
                        return 0;
                    }
                }
            }
        }
    }
    return 1;
}

bool cmp(point a1, point b1){
    return a1.v < b1.v;
}

int main(){
    while(1){
        cin >> n >> di;
        if (n == 0 && di == 0) {
            break;
        }
        for (int i = 1; i <= n; ++i){
            cin >> p[i].v;
            p[i].id = i;
        }
        
        sort(p + 1, p + n + 1, cmp);
        for (int i = 1; i < n; ++i){
            int x = p[i].id, y = p[i+1].id;
            int u = min(x, y), v = max (x, y);
            G[u].push_back((node){v, di});
        }
        
        for (int i = 2; i <= n; ++i) {
            G[i].push_back ((node){i - 1, -1});
        }
        
        int minx = min (p[1].id, p[n].id);
        int maxx = max (p[1].id, p[n].id);
        
        if(spfa(minx)){
            printf("%d\n", d[maxx]);
    	} else {
            printf("-1\n");
        }
        
        for(int i = 0; i <= n; i++){
	        G[i].clear();
	    }
    }
    return 0;
}

